precision mediump float;
const float PI=3.14159265359;
float sdCircle(vec2 p, float r) {
    return length(p) - r;
}


float sdBox(vec2 p, vec2 b) {
    vec2 d = abs(p) - b;
    return length(max(d,0.))+min(max(d.x,d.y),0.);
}

mat2 rotation2d(float angle){
    float s=sin(angle);
    float c=cos(angle);

    return mat2(
        c,-s,
        s,c
    );
}

vec2 rotate(vec2 v,float angle){
    return rotation2d(angle)*v;
}


float sdEquilateralTriangle(in vec2 p,in float r)
{
    const float k=sqrt(3.);
    p.x=abs(p.x)-r;
    p.y=p.y+r/k;
    if(p.x+k*p.y>0.)p=vec2(p.x-k*p.y,-k*p.x-p.y)/2.;
    p.x-=clamp(p.x,-2.*r,0.);
    return-length(p)*sign(p.y);
}

float opRound(in float d,in float r)
{
    return d-r;
}

float opOnion(in float d,in float r)
{
    return abs(d)-r;
}


void mainImage(out vec4 fragColor,in vec2 fragCoord){
    vec2 uv=fragCoord/iResolution.xy;

    // uv = fract(uv * vec2(2.0,2.0));
    uv = (uv - 0.5) * 2.;
    // float d = sdEquilateralTriangle(uv,0.5);
    float d = sdBox(uv, vec2(0.4,0.4)); 
    float c = smoothstep(0., 0.02, d);

    // fragColor = vec4(vec3(c), 1.);
    d=opOnion(c,.2);
    fragColor = vec4(vec3(d),1.);

}
